package org.chen.wordwave.act.adapter;

import static org.chen.wordwave.bean.CalendarStatus.BLANK;
import static org.chen.wordwave.bean.CalendarStatus.NOT_CHECKED_IN;
import static org.chen.wordwave.bean.CalendarStatus.OTHER;
import static org.chen.wordwave.bean.CalendarStatus.SIGNED_IN;
import static org.chen.wordwave.bean.CalendarStatus.TODAY;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import org.chen.wordwave.R;
import org.chen.wordwave.bean.CalendarDate;

import java.util.List;

public class CalendarAdapter extends RecyclerView.Adapter<CalendarAdapter.MyViewHolder> {

    private List<CalendarDate> calendarDateList;
    private Context mContext;

    public CalendarAdapter(List<CalendarDate> calendarDateList, Context context) {
        this.calendarDateList = calendarDateList;
        this.mContext=context;
    }

    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = View.inflate(mContext, R.layout.custom_calendar_item,null);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
        CalendarDate calendarDate=calendarDateList.get(position);
        switch (calendarDate.getCalendarStatus()){

            case SIGNED_IN:
                holder.tv_yiqiandao.setVisibility(View.VISIBLE);
                holder.tv_weiqiandao.setVisibility(View.GONE);
                holder.tv_jinri.setVisibility(View.GONE);
                holder.tv_kongbai.setVisibility(View.GONE);
                holder.tv_weidao.setVisibility(View.GONE);
                holder.tv_yiqiandao.setText(String.valueOf(calendarDate.getDay()));
                break;
            case NOT_CHECKED_IN:
                holder.tv_yiqiandao.setVisibility(View.GONE);
                holder.tv_weiqiandao.setVisibility(View.VISIBLE);
                holder.tv_jinri.setVisibility(View.GONE);
                holder.tv_kongbai.setVisibility(View.GONE);
                holder.tv_weidao.setVisibility(View.GONE);
                holder.tv_weiqiandao.setText(String.valueOf(calendarDate.getDay()));
                break;
            case TODAY:
                holder.tv_yiqiandao.setVisibility(View.GONE);
                holder.tv_weiqiandao.setVisibility(View.GONE);
                holder.tv_jinri.setVisibility(View.VISIBLE);
                holder.tv_kongbai.setVisibility(View.GONE);
                holder.tv_weidao.setVisibility(View.GONE);
                holder.tv_jinri.setText(String.valueOf(calendarDate.getDay()));
                break;
            case BLANK:
                holder.tv_yiqiandao.setVisibility(View.GONE);
                holder.tv_weiqiandao.setVisibility(View.GONE);
                holder.tv_jinri.setVisibility(View.GONE);
                holder.tv_kongbai.setVisibility(View.VISIBLE);
                holder.tv_weidao.setVisibility(View.GONE);
                break;
            case OTHER:
                holder.tv_yiqiandao.setVisibility(View.GONE);
                holder.tv_weiqiandao.setVisibility(View.GONE);
                holder.tv_jinri.setVisibility(View.GONE);
                holder.tv_kongbai.setVisibility(View.GONE);
                holder.tv_weidao.setVisibility(View.VISIBLE);
                holder.tv_weidao.setText(String.valueOf(calendarDate.getDay()));
                break;
        }



    }

    @Override
    public int getItemCount() {
        return calendarDateList.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder {

        private TextView tv_yiqiandao,tv_weiqiandao,tv_jinri,tv_weidao,tv_kongbai;

        public MyViewHolder(View itemView) {
            super(itemView);
            tv_yiqiandao = itemView.findViewById(R.id.tv_yiqiandao);
            tv_weiqiandao = itemView.findViewById(R.id.tv_weiqiandao);
            tv_jinri = itemView.findViewById(R.id.tv_jinri);
            tv_weidao = itemView.findViewById(R.id.tv_weidao);
            tv_kongbai = itemView.findViewById(R.id.tv_kongbai);
        }
    }
}
